﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;
using System.Reflection;
namespace JumpingMan
{
    class ListofPlayer: Player
    {
        public List<Player> players;
        //StreamReader sr;
        public ListofPlayer()
        {
            players = new List<Player>();
        }
        public void ReadPlayersFromFile()
        {
            
            
            using(StreamReader sr = new StreamReader(@"highscore.txt"))
            {
                string text;
                while ((text = sr.ReadLine()) != null)
                {
                    string minutes = "";
                    string seconds = "";
                    Player player = new Player();                   
                    int length = text.Length;
                    minutes += text[0];                   
                    seconds += text[2];
                    seconds += text[3];
                    player.minutes = Convert.ToInt32(minutes);
                    player.seconds = Convert.ToInt32(seconds);
                    player.time = (player.minutes * 60) + player.seconds;
                    for (int i = 5; i < length; i++)
                    {
                        player.namn += text[i];
                    }
                    this.players.Add(player);
                }
            }
            

        }
        //public void WritePlayerResultsToMessageBox()
        //{
        //    int counter = 0;
            
        //    foreach (Player player in players)
        //    {
        //        string textSeconds = "";
        //        string textMinute = "";
        //        string textName = "";
        //        if (counter < 10)
        //        {
        //            textMinute += player.minutes.ToString();
        //            textMinute += ":";
        //            if (player.seconds < 10)
        //            {
        //                textMinute += "0";
        //                textMinute += player.seconds.ToString();
        //                textMinute += " ";
        //            }
        //            else
        //            {
        //                textMinute += player.seconds.ToString();
        //                textMinute += " ";
        //            }
                    
        //            labelTime.Text = textMinute;
        //            textName += player.namn;
                    
                   
                    
        //            counter++;                  
        //        }
        //    }
            
            //return text;
        //}
        //public string GetPlayerName()
        //{
        //}
        //public string GetPlayerTime()
        //{
        //}
        public void SortTheListOfPlayer()
        {
            players.Sort((s2, s1) => s1.time.CompareTo(s2.time));
            
            
            
        }
    }
}
